﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

// TODO Need to change the category for a drop-down list of categories (sub-categories).
// TODO Do we want to load all historical transactions so that we can display the current matches, this could be a button to load
namespace Money.Plugins.Import.TescoImport
{
    public partial class CreditCardCategoriesForm : Form
    {

        public delegate object GetTransactions(string category);
        private Categories _categories;

        GetTransactions _transHandler;
 
        public CreditCardCategoriesForm(GetTransactions transHandler, Categories categories)
        {
            InitializeComponent();

            _categories = categories;
            _transHandler = transHandler;

            _categoryMapGrid.AutoGenerateColumns = false;
            _transactionGrid.AutoGenerateColumns = false;
        }

        private void ConfigureDataGrids()
        {
            clmSubCategory.DataSource = _categories;
            clmSubCategory.ValueMember = "Id";
            clmSubCategory.DisplayMember = "Name";
        }

        private void _categoryMapGrid_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            // TODO : We need to update the bottom grid view to show transactions of this type.
            if (_transHandler != null)
            {
                string creditCardCategory;

                creditCardCategory = _categoryMapGrid.Rows[e.RowIndex].Cells[0].Value.ToString();
                _transactionGrid.DataSource = _transHandler(creditCardCategory);
            }
        }

        private void CreditCardCategories_Load(object sender, EventArgs e)
        {
            ConfigureDataGrids();
        }

        private void dgCategories_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }
    }
}
